package tr.edu.metu.is.mega.server.business;

import java.util.ArrayList;
import java.util.List;

import tr.edu.metu.is.mega.common.dto.ActivityDTO;
import tr.edu.metu.is.mega.server.dao.ActivityDAO;
import tr.edu.metu.is.mega.server.entity.Activity;
import tr.edu.metu.is.mega.server.entity.Submission;
import tr.edu.metu.is.mega.server.entity.Team;

/**
 * Class to manage announcements.
 */
public class ActivityManager {

    private final ActivityDAO dao;

    private final ActivityDTOHelper helper;

    /**
     * Default constructor.
     */
    public ActivityManager() {
        dao = new ActivityDAO();
        helper = new ActivityDTOHelper();
    }

    /**
     * Gets activities based on team id.
     * 
     * @param teamId team to retrieve
     * @return list of activities of that team
     */
    public List<ActivityDTO> getActivities(int teamId) {
        Activity example = new Activity();
        Submission submissionEx = new Submission();
        Team team = new Team();
        team.setPkid(teamId);
        submissionEx.setTeam(team);
        example.setSubmissions(new ArrayList<Submission>());
        example.getSubmissions().add(submissionEx);
        List<Activity> findByNamedNativeQuery = dao.findByExample(example, false);
        return helper.toDTO(findByNamedNativeQuery);
    }

}
